<script>
	$(document).ready(function(){
		$('#reset').click(function(){
			location.href = '<?php echo $this->url(array('module' => 'store', 'controller' => 'product', 'action' => 'list','id_store'=>$this->id_store), '', true) ?>';
		});
		
		$('select').change(function(){
			if($(this).val()!=0){
				$(this).attr('style', 'color:#000000');
			}else{
				$(this).attr('style', 'color:#cccccc');
			}
		});
	
		$('input[type=text]').change(function(){
			if($(this).val()!='keyword' && $(this).val()!=''){
				$(this).attr('style', 'color:#000000');
			}else{
				$(this).attr('style', 'color:#cccccc');
			}
		});
	});
</script>
<?php
	$backLink = base64_encode(urlencode($this->url(array()) . '?' . http_build_query($_GET)));
	$arrCommon = array('back_link' => $backLink, 'form_submitted' => null, 'submit' => null,'id' => NULL);
?>
<!--Form Panel-->
<script language="javascript" type="text/javascript">       
    addTab("<?php echo Core_Util::escapeForJS($this->store->getName());?>",'<?php echo $this->url(array('action' => 'list'))?>');
</script>
<table border="0" class="bread-crumb">
	<tr>
		<td ><?php echo $this->partial('breadcrum-menu.phtml', array('new_orders' => $this->new_orders, 'id_store' => $this->store->id)) ?></td>
		<td style="text-align: right;">
			<a class="underline non_space" href="<?php echo $this->url(array('action' => 'create')); ?>">
				<img src="img/add.png" class="bordernone" height="11" width="11" /><?php echo $this->translate('NEW_PRODUCT_LABEL') ?>
			</a>
		</td>
	</tr>
</table>
<?php echo $this->form ?>
<?php if(!empty($this->pageValues['form_submitted'])):?>	
	<div class="title_search_result">
		<?php 
			$this->pageValues['item_count'] = $this->paginator->getTotalItemCount();
			$order = array('url','item_count','keyword','category','status');
			$keys  = array('keyword', 'category','status');
			$text_search_results = $this->results($this->form, $keys, $this->pageValues, $order, $this->url);
			$text_search_results = Core_Util::removeLink($text_search_results);
			echo $text_search_results;
		?>
		- <a id="reset" onClick="clearFormDataInBackend();return false;" href="#" target="">Reset</a>
	</div>
<?php endif;?>

<?php if (count($this->messages)) : ?>
	<div class="ms_message">
		<?php foreach ($this->messages as $message) : ?>
			<?php echo $this->translate($message); ?>
		<?php endforeach; ?>
	</div>
<?php endif; ?>

<?php if (count($this->paginator)): ?>
<table class="sm_tbl_classic" id="list_store">
<thead>
	<tr>
        <!--name-->
		<th style="width:330px;">
			<?php echo $this->partial('store/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'product_name',
					'sort_default'  => 'ASC'
				),
				'label' => 'PRODUCT_HEADER_NAME',                
			)) ?>            
		</th>  
        <!--SKU-->
		<th style="width:140px;">
            <?php echo $this->partial('store/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'sku',
					'sort_default'  => 'DESC'
				),
				'label' => 'PRODUCT_HEADER_SKU'
			)) ?>			
		</th>
        <!--number_buys-->
		<th style="width:110px;">
            <?php echo $this->partial('store/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'number_buys',
					'sort_default'  => 'DESC'
				),
				'label' => 'PRODUCT_HEADER_BUY'
			)) ?>			
		</th>
        <!--time_created-->
        <th style="width:90px;">
            <?php echo $this->partial('store/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'time_created',
					'sort_default'  => 'DESC'                    
				),
				'label' => 'PRODUCT_HEADER_DATE',
                'is_default'    => true
			)) ?>				
		</th>
        <!--status-->
        <th style="width:80px;">
             <?php echo $this->partial('store/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'status',
					'sort_default'  => 'ASC'
				),
				'label' => 'PRODUCT_HEADER_STATUS'
			)) ?>				
		</th>
        <!--Actions-->
        <th>
			<span>
				<?php echo $this->translate('PRODUCT_HEADER_ACTION') ?>
			</span>
		</th>
        
	</tr>
</thead>
<tbody>
	<?php
		foreach ($this->paginator->getCurrentItems() as $product):		
	?>
	<tr>
        <!-- Product -->
		<td>
			<p>
				<a  class="underline" href="<?php echo $this->url(array('action' => 'edit','id' => $product->id, 'back_link' => $backLink)); ?>">
					<?php echo $this->escape($product->name) ?>
				</a>
			</p>
			<ul class="product_images">
				<?php $i = 0;?>
				<?php foreach ($product->getListProductImages() as $image): ?>
					<?php if ($i < MAX_PRODUCT_LIST_IMAGE):?>
				<li>
					<div style="line-height:0px; width: 45px; display:inline-block; text-align:center;">
					<a href="">
						<img src="<?php echo STATIC_URL . '/upload/product/thumbnail/' .$image->image ?>">
					</a>
					</div>
				</li>
					<?php $i++;?>
					<?php else:?>
					<?php break;?>
					<?php endif;?>
				<?php endforeach;?>
			</ul>
		</td>
        <!-- Product -->
		<td>
			<p>
				<?php echo $this->escape($product->sku) ?>
			</p>
		</td>
        
        <!--Number buys-->
		<td align='right'>
			<?php echo $product->number_buys ?>
		</td>
        <!--Create date-->
		<td>            
			<?php echo date('d-m-Y',$product->time_created) ?>
		</td>
        <!--Status-->        
		<td>		
            <span class="tooltip_label" title="<?php echo $this->translate('TOOTIP_' . $product->getStatus());?>">
                <?php echo $this->translate($product->getStatus()) ?>
            </span>
		</td>
        <!--Action-->
		<td>
			<div style="float:right">
				<select onchange="performAction.call(this,<?php echo $product->id;?>)">
					<option value="">-select-</option>
					<option value="edit" >edit</option>
					<?php if ($product->status != Core_Model_DbTable_Products::STATUS_HIDDEN):?>
						<option value="hide">hide</option> 
                       <?php echo $this->translate($product->getStatus()) ?>

					<?php else:?>
						<option value="show">show</option>
					<?php endif;?>
					<option value="delete" >delete</option>
				</select>
			</div>
		</td>
	</tr>
	<?php endforeach;?>
</tbody>
</table>
<?php echo $this->paginationControl(
		$this->paginator,
		'Sliding',
		'store/pagination_control.phtml',
		array(
			'param_page'    => PARAM_PAGE_NAME,
			'query'         => $_GET
		)
	);
?>
<?php elseif( !isset($_REQUEST['form_submitted']) ):?>
<div class="sm_paginator_item_empty">
     <?php echo $this->translate('NO_PRODUCT_AVAILABLE')?>
	-
	<a href="<?php echo $this->url(array('controller' => 'product', 'action' =>'create','id' => NULL))?>">
		<?php echo $this->translate('PRODUCT_MENU_CREATE') ?>	
	</a>
</div>
<?php endif;?>
<div class="en_image"">
	<img src="">
</div>
<script language="javascript">
	function performAction(id_product)
	{
        var action = this.value;
		switch (action)
		{            
			case 'edit':                
				location.href="<?php echo $this->url($arrCommon + array('action' => 'edit')); ?>/id/" + id_product ;
				break;
			case 'show':
				var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_SHOW_PRODUCT') ?>');
				if (!ok) break;
				location.href="<?php echo $this->url($arrCommon + array('action' => 'show')); ?>/id/" + id_product ;
				break;
           	case 'hide':
				var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_HIDE_PRODUCT') ?>');
				if (!ok) break;
				location.href="<?php echo $this->url($arrCommon + array('action' => 'hide')); ?>/id/" + id_product ;
				break;
			case 'delete':
				var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_DELETE_PRODUCT') ?>');
				if (!ok) break;
				location.href="<?php echo $this->url($arrCommon + array('action' => 'delete')); ?>/id/" + id_product ;
				break;
		}
		this.selectedIndex = 0;
	}
	$('.product_images a').ymProductImage({
		'div' : 'en_image'
	});
    $(".tooltip_label").tipsy({html:true,gravity: $.fn.tipsy.autoNS});
</script>